home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE06 / VBX / SWITCH2.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-01-02  |  3.9 KB  |  135 lines

  1. {********************************************}
  2. {*                                          *}
  3. {*  SWITCH2.PAS generated from SWITCH.VBX   *}
  4. {* Modified to make an abstract Custom VBX  *)
  5. (* ancestor control                         *)     
  6. {*                                          *}
  7. {********************************************}
  8. unit Switch2 ;
  9.  
  10. interface
  11.  
  12. uses 
  13.   SysUtils, 
  14.   Classes, 
  15.   Graphics, 
  16.   Forms, 
  17.   Controls, 
  18.   VBXCtrl, 
  19.   BIVBX;
  20.  
  21. { $DEFINE InitTBiCustomSwitch}
  22. {^- Remove space to enable default init data -- See documentation. }
  23.  
  24. type
  25.   TBiCustomSwitchOnEvent = procedure (Sender: TObject) of object;
  26.   TBiCustomSwitchOffEvent = procedure (Sender: TObject) of object;
  27.  
  28.   { TBiCustomSwitch }
  29.  
  30.   TBiCustomSwitch = class(TVBXControl)
  31.   protected
  32.     FOnOn: TBiCustomSwitchOnEvent;
  33.     FOnOff: TBiCustomSwitchOffEvent;
  34.     { Event handler }
  35.     procedure HandleVBXEvent(var Message: TWMVBXFireEvent); override;
  36.   public
  37.     constructor Create(AOwner: TComponent); override;
  38.     property Index: TVBInteger index 1 read GetIntProp;
  39.   {published}
  40.     property Visible;
  41.     property ForeColor: TColor index 10 read GetColorProp write SetColorProp
  42.       default -2147483640;
  43.     property BackColor: TColor index 11 read GetColorProp write SetColorProp
  44.       default -2147483633;
  45.     property Caption;
  46.     property BorderStyle: TVBEnum index 13 read GetEnumProp write SetEnumProp
  47.       default 0;
  48.     property pOn: Boolean index 14 read GetBoolProp write SetBoolProp;
  49.     property TextPosition: TVBEnum index 15 read GetEnumProp write
  50.       SetEnumProp default 0;
  51.     property Font;
  52.     property ParentFont;
  53.     property TabStop;
  54.     property TabOrder;
  55.     property DragMode;
  56.     property DragCursor;
  57.     property OnOn: TBiCustomSwitchOnEvent read FOnOn write FOnOn;
  58.     property OnOff: TBiCustomSwitchOffEvent read FOnOff write FOnOff;
  59.     property OnMouseMove;
  60.     property OnMouseDown;
  61.     property OnMouseUp;
  62.     property OnKeyDown;
  63.     property OnKeyUp;
  64.     property OnKeyPress;
  65.     property OnEnter;
  66.     property OnExit;
  67.     property OnDragOver;
  68.     property OnDragDrop;
  69.     property OnEndDrag;
  70.   published
  71.   end;
  72.  
  73. procedure Register;
  74.  
  75. implementation
  76.  
  77. { Default form data for TBiCustomSwitch }
  78.  
  79. {$IFDEF InitTBiCustomSwitch}
  80.  
  81. const
  82.   TBiCustomSwitchInitLen = 57;
  83.  
  84. procedure TBiCustomSwitchInitData; near; assembler;
  85. asm
  86.     DB    $00,$08,$42,$69,$53,$77,$69,$74,$63,$68,$01,$00,$00,$02,$06,$FF
  87.     DB    $FF,$08,$00,$0A,$00,$00,$00,$00,$0B,$0F,$00,$00,$80,$0C,$08,$42
  88.     DB    $49,$53,$57,$49,$54,$43,$48,$0D,$00,$0E,$00,$00,$0F,$00,$10,$00
  89.     DB    $16,$00,$00,$17,$00,$00,$18,$00,$FF
  90. end;
  91.  
  92. {$ENDIF}
  93.  
  94. { TBiCustomSwitch }
  95.  
  96. constructor TBiCustomSwitch.Create(AOwner: TComponent);
  97. begin
  98.   FVBXFile := StrNew('CUSTOMSWITCH.VBX');
  99.   FVBXClass := StrNew('BICUSTOMSWITCH');
  100.   SetBounds(0, 0, 80, 32);
  101.   inherited Create(AOwner);
  102.   ControlStyle := ControlStyle - [csCaptureMouse, csClickEvents];
  103.   TabStop := True;
  104.   FVBXFlags := [vfProcessMnemonic];
  105.   {$IFDEF InitTBiCustomSwitch}
  106.   FHForm := VBXCreateFormFile(TBiCustomSwitchInitLen, @TBiCustomSwitchInitData);
  107.   {$ENDIF}
  108. end;
  109.  
  110. procedure TBiCustomSwitch.HandleVBXEvent(var Message: TWMVBXFireEvent);
  111. begin
  112.   case Message.VBXEvent^.EventIndex of
  113.     0: DispatchCustomEvent(FOnOn, Message, 0);
  114.     1: DispatchCustomEvent(FOnOff, Message, 1);
  115.     2: DispatchMouseMoveEvent(OnMouseMove, Message);
  116.     3: DispatchMouseEvent(OnMouseDown, Message);
  117.     4: DispatchMouseEvent(OnMouseUp, Message);
  118.     5: DispatchKeyEvent(OnKeyDown, Message);
  119.     6: DispatchKeyEvent(OnKeyUp, Message);
  120.     7: DispatchKeyPressedEvent(OnKeyPress, Message);
  121.     8: begin end; { VCL Handles OnGotFocus }
  122.     9: begin end; { VCL Handles OnLostFocus }
  123.     10: begin end; { VCL Handles OnDragOver }
  124.     11: begin end; { VCL Handles OnDragDrop }
  125.   end;
  126. end;
  127.  
  128. { Designer registration }
  129. procedure Register;
  130. begin
  131.   RegisterComponents('VBX', [TBiCustomSwitch]);
  132. end;
  133.  
  134. end.
  135.